<template>
  <t-dialog :header="header" :visible.sync="visible" :onClose="closeDialog"     :closeOnOverlayClick="false"
            @confirm="onSubmit" :confirmBtn="{
        content: loading?'提交中...':'确认',
        theme: 'primary',
        loading: loading,
      }"  width="80%"
            top="5%">
   <div style="height: 65vh">
     <t-form ref="form" :data="formData" labelWidth="120px" :rules="rules">
       <t-row style="row-gap:24px">
         <t-col :span="12">
           <t-form-item label="论文名称" name="name">
             <t-input clearable v-model="formData.name" placeholder="请输入内容"></t-input>
           </t-form-item>
         </t-col>
         <t-col :span="6">
           <t-form-item label="刊号(ISSN)" name="issn">
             <t-input  clearable style="width:390px" v-model="formData.issn" placeholder="请输入内容"></t-input>
           </t-form-item>
         </t-col>
         <t-col :span="6">
           <t-form-item label="主办单位" name="hostDept">
             <t-input clearable style="width:390px" v-model="formData.hostDept" placeholder="请输入内容"></t-input>
           </t-form-item>
         </t-col>
         <t-col :span="6">
           <t-form-item label="刊物名称" name="publicationName">
             <t-input style="width:390px" v-model="formData.publicationName" placeholder="请输入内容"></t-input>
           </t-form-item>
         </t-col>
         <t-col :span="6">
           <t-form-item label="个人排名" name="thesisRanking">
             <t-select style="width:390px" clearable filterable v-model="formData.thesisRanking" :options="dict.type.thesis_ranking">
             </t-select>
           </t-form-item>
         </t-col>
         <t-col :span="6">
           <t-form-item label="出版年月" name="publishDate">
             <t-date-picker style="width:390px" clearable v-model="formData.publishDate"></t-date-picker>
           </t-form-item>
         </t-col>
         <t-col :span="6">
           <t-form-item label="完成字数" name="completeWordCount">
             <t-input-adornment append="千字">
               <t-input-number placeholder="请输入至多三位整数"  :allowInputOverLimit="false" clearable style="width: calc(390px - 45px)"
                               v-model="formData.completeWordCount"
                               theme="normal"
                               :min="0"></t-input-number>
             </t-input-adornment>
           </t-form-item>
         </t-col>
         <t-col :span="6">
           <t-form-item label="级别" name="paperLevel">
             <t-select style="width:390px" clearable filterable v-model="formData.paperLevel" :options="dict.type.paper_level">
             </t-select>
           </t-form-item>
         </t-col>
         <t-col :span="12">
           <t-form-item label="备注" name="note">
             <t-textarea
               clearable :autosize="{minRows: 5}"
               v-model="formData.note"
               placeholder="明确标明符合申报条件的具体条款"
             />
           </t-form-item>
         </t-col>
         <t-col :span="6">
           <t-form-item label="检索验证地址" name="verifyAddress">
             <t-input clearable style="width:390px" v-model="formData.verifyAddress" placeholder="请输入内容"></t-input>
           </t-form-item>
         </t-col>

         <t-col :span="12">
           <t-table size="small" row-key="id" :columns="fileColumns" :data="fileData">
             <template #op="{row}">
               <file-upload  v-model="row.fileIds" :moduleKey="row.moduleKey"
                            :fileList="row.fileLists"
                            :multiple="true" tips="">
                 <t-button variant="outline">
                   <t-icon name="cloud-upload" slot="icon"/>
                   点击上传
                 </t-button>
               </file-upload>
             </template>
           </t-table>
         </t-col>
       </t-row>
     </t-form>
   </div>
  </t-dialog>
</template>

<script>
import FileUpload from "@/components/FileUpload/index.vue"
import {getFiles} from "@/api/common";

export default {
  name: "add-edit-thesis",
  dicts: ["paper_level","thesis_ranking"],
  props: ['header', 'objId', 'parentId'],
  data(){
    return {
      menuOptions: [],
      visible: true,
      loading: false,
      fileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "left",
        },
      ],
      fileData: [
        {
          id: 1,
          c1: "期刊封面",
          c2: "是",
          moduleKey: "projectCXBG",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 2,
          c1: "期刊目录",
          c2: "是",
          moduleKey: "projectCXBG",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 3,
          c1: "期刊版权页,检索证明",
          c2: "是",
          moduleKey: "projectCXBG",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 4,
          c1: "上传正文",
          c2: "是",
          moduleKey: "projectCXBG",
          fileIds: [],
          fileLists: [],
        },
      ],
      formData: {
        name: null,
        issn: '',
        hostDept: '',
        publicationName: '',
        thesisRanking: '',
        publishDate: '',
        completeWordCount: null,
        paperLevel: '',
        note: '',
        verifyAddress: ''
      },
      rules: {
        name: [
          {required: true, message: "论文名称不能为空"}
        ],
        issn: [
          {required: true, message: "刊号(ISSN)不能为空"}
        ],
        hostDept: [
          {required: true, message: "主办单位不能为空"}
        ],
        publicationName: [
          {required: true, message: "刊物名称不能为空"}
        ],
        thesisRanking: [
          {required: true, message: "个人排名不能为空"}
        ],
      }
    }
  },
  created() {
    this.getTreeSelect();
  },
  methods:{
    onSubmit() {
      this.$refs.form.validate().then((validateResult) => {
        if (validateResult === true) {
          this.loading = true;
          if (this.objId) {
            this.$api.kjxm.review.teamUpdate(this.formData
            ).then((response) => {
              this.$message.success("修改成功");
              this.$emit("reload");
              this.$emit("update:visible", false);
              this.loading = false;
            }).catch((e) => {
              this.loading = false;
              this.$message.error(e.toString());
            });
          } else {

            this.$api.kjxm.review.teamAdd(this.formData).then((response) => {
              this.$message.success("新增成功");
              this.$emit("reload");
              this.$emit("update:visible", false);
              this.loading = false;
            }).catch((e) => {
              this.loading = false;
              this.$message.error(e.toString());
            });
          }
        }
      });
    },
    /** 查询菜单下拉树结构 */
    getTreeSelect() {
      return this.$api.system.result.treeselect().then(response => {
        this.menuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style scoped>

</style>
